package com.shuda.db.user.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shuda.db.user.entity.Role;
import com.shuda.db.user.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RoleDao {
    
    @Autowired
    private RoleMapper roleMapper;
    
    public Role getById(Long id) {
        return roleMapper.selectById(id);
    }
    
    public Role getByRoleCode(String roleCode) {
        QueryWrapper<Role> wrapper = new QueryWrapper<>();
        wrapper.eq("role_code", roleCode);
        return roleMapper.selectOne(wrapper);
    }
    
    public List<Role> getList(Page<Role> page) {
        return roleMapper.selectPage(page, null).getRecords();
    }
    
    public int insert(Role role) {
        return roleMapper.insert(role);
    }
    
    public int update(Role role) {
        return roleMapper.updateById(role);
    }
    
    public int delete(Long id) {
        return roleMapper.deleteById(id);
    }
}